package com.zhanghu.backendZray.enums;

import com.zhanghu.backendZray.pojo.request.mail.NotifySettingRequest;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.Assert;

/**
 * @author ZhangDong
 * @date 2024/8/30 16:18
 */
@Getter
@AllArgsConstructor
public enum NotifyTypeEnum {

    MAIL((byte) 0, "邮件", true),
    BARK((byte) 1, "Bark", true),
    MESSAGE((byte) 2, "短信", false),
    ;
    private Byte type;
    private String des;
    private boolean support;

    /**
     * 验证入参的必填性
     * @param request
     */
    public static void validRequest(NotifySettingRequest request) {
        Byte temp = request.getType();
        if (MAIL.type.equals(temp)) {
            Assert.notNull(request.getMail(), "邮箱不能为空");
        } else if (BARK.type.equals(temp)) {
            Assert.notNull(request.getBarkUrl(), "Bark地址不能为空");
        }
    }

    public static NotifyTypeEnum getByType(Byte type) {
        NotifyTypeEnum[] values = values();
        for (NotifyTypeEnum value : values) {
            if (value.getType().equals(type)) {
                return value;
            }
        }
        return null;
    }

}
